package cn;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginDispatchServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String myUserid=req.getParameter("userid");
        String myPassword=req.getParameter("password");
        // String myUsername=req.getParameter("username");

        boolean loginFlag=false;
        try{
            DatabaseConnection databaseConnection=new DatabaseConnection();
            IUserDAO iUserDAO=new UserDAOImpl(databaseConnection.getConnection());
            loginFlag=iUserDAO.findLogin(myUserid,myPassword);
        }catch (Exception e){
            e.printStackTrace();
        }

        RequestDispatcher rd;
        if(loginFlag){
            rd=req.getRequestDispatcher("/Login/Home.jsp");
        }else{
            rd=req.getRequestDispatcher("/20211123/Failure.jsp");
        }
        rd.forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}